<template>
  <div class="content">
    <div class="header">
      <slot name="header"> </slot>
    </div>
    <el-table
      :data="Listdata"
      border
      @selection-change="handleSelectionChange"
      v-bind="childrenProps"
    >
      <!-- <el-table-column label="用户名" prop="name"></el-table-column>
        <el-table-column label="真实姓名" prop="realname"></el-table-column>
        <el-table-column label="电话号码" prop="cellphone"></el-table-column> -->
      <el-table-column v-if="showSeleteColumn" type="selection" align="center" width="80%" />
      <el-table-column
        v-if="showIndexColumn"
        type="index"
        label="序号"
        align="center"
        width="80%"
      />
      <template v-for="propItem in propList" :key="propItem.id">
        <el-table-column v-bind="propItem" align="center" show-overflow-tooltip>
          <template #default="{ row }">
            <slot :name="propItem.slotName" :row="row">
              {{ row[propItem.prop] }}
            </slot>
            <!-- <el-button type="primary">
            </el-button> -->
          </template>
        </el-table-column>
      </template>
    </el-table>
    <div class="footer" v-if="showFooter">
      <slot name="footer">
        <el-pagination
          :current-page="page.current"
          :page-size="page.pageSize"
          :page-sizes="[10, 20, 30, 40]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="ListCount"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </slot>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'

export default defineComponent({
  props: {
    Listdata: {
      type: Array,
      default: () => []
    },
    ListCount: {
      type: Number,
      default: 0
    },
    propList: {
      type: Array as any,
      default: () => []
    },
    showIndexColumn: {
      type: Boolean,
      default: false
    },
    showSeleteColumn: {
      type: Boolean,
      default: false
    },
    page: {
      type: Object,
      default: () => ({ currentPage: 0, pageSize: 10 })
    },
    childrenProps: {
      type: Object,
      default: () => ({})
    },
    showFooter: {
      type: Boolean,
      default: true
    }
  },
  emits: ['selectionChange', 'update:page'],
  setup(props, { emit }) {
    const handleSelectionChange = (value: any) => {
      emit('selectionChange', value)
    }
    const handleCurrentChange = (currentPage: number) => {
      emit('update:page', { ...props.page, currentPage })
    }
    const handleSizeChange = (pageSize: number) => {
      emit('update:page', { ...props.page, pageSize })
    }

    const currentPage = ref(1)
    const pageSize = ref(10)

    return {
      handleSelectionChange,
      handleSizeChange,
      handleCurrentChange,
      currentPage,
      pageSize
    }
  }
})
</script>

<style lang="less" scoped>
/deep/ .el-table {
  background-color: transparent; //这是设置透明背景色
  --el-table-tr-bg-color: transparent;
  --el-table-header-bg-color: transparent;
  color: #00ffaf;
  --el-table-border-color: #661e93;
}
.content {
  padding: 20px;
  // border-top: 20px solid #eee;
}

.footer {
  margin: 20px 0;
  display: flex;
  justify-content: end;
}
</style>
